﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Documents;
using System.IO;

namespace CharacterCreation.Controls {
    public class MyRichTextBox : RichTextBox {
        

        /// <summary>
        /// The Text property.
        /// </summary>
        public string Text {
            get {
                TextRange range = new TextRange(this.Document.ContentStart, this.Document.ContentEnd);
                MemoryStream ms = new MemoryStream();
                range.Save(ms, DataFormats.Xaml);
                string xamlString = ASCIIEncoding.Default.GetString(ms.ToArray());

                return xamlString; 
            }
            set {
                TextRange range = new TextRange(this.Document.ContentStart, this.Document.ContentEnd);
                System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
                MemoryStream ms = new MemoryStream(enc.GetBytes(value));
                range.Load(ms, DataFormats.Xaml);

                SetValue(TextProperty, value); 
            }
        }
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string), typeof(MyRichTextBox), null);               
                
                
    }
}
